package com.gujiangbo.application.utils;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.PropertyPreFilter;
import java.util.HashSet;
import java.util.Set;

public class JsonIgnoreFilter implements PropertyPreFilter {
	private final Class<?> clazz;
	private final Set<String> includes = new HashSet();
	private final Set<String> excludes = new HashSet();

	public JsonIgnoreFilter(String... properties) {
		this(null, properties);
	}

	public JsonIgnoreFilter(Class<?> clazz, String... properties) {
		this.clazz = clazz;
		String[] arrayOfString;
		int j = (arrayOfString = properties).length;
		for (int i = 0; i < j; i++) {
			String item = arrayOfString[i];
			if (item != null) {
				this.excludes.add(item);
			}
		}
	}

	public Class<?> getClazz() {
		return this.clazz;
	}

	public Set<String> getIncludes() {
		return this.includes;
	}

	public Set<String> getExcludes() {
		return this.excludes;
	}

	public boolean apply(JSONSerializer serializer, Object source, String name) {
		if (source == null) {
			return true;
		}
		if ((this.clazz != null) && (!this.clazz.isInstance(source))) {
			return true;
		}
		if (this.excludes.contains(name)) {
			return false;
		}
		if ((this.includes.size() == 0) || (this.includes.contains(name))) {
			return true;
		}
		return false;
	}
}
